<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>

	
		<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
		<meta http-equiv="Content-Language" content="en-us">

		<title>Django | Pagination | Django Documentation</title>

		<meta name="ROBOTS" content="ALL">
		<meta http-equiv="imagetoolbar" content="no">
		<meta name="MSSmartTagsPreventParsing" content="true">
		<meta name="Copyright" content="This site's design and contents Copyright (c) 2005  Lawrence Journal-World.">

		<meta name="keywords" content="Python, Django, framework, open-source">
		<meta name="description" content="Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.">

		<link href="Django%20%7C%20Pagination%20%7C%20Django%20Documentation_files/base.css" rel="stylesheet" type="text/css" media="screen">
		<link href="Django%20%7C%20Pagination%20%7C%20Django%20Documentation_files/print.css" rel="stylesheet" type="text/css" media="print">
      
  
  <style type="text/css" media="screen">
    #docs-search {
      color: #000;
      float: right;
    }
    #docs-search form {
      font-size: 92%;
      margin: 0;
      padding: 1em 1em 0;
      white-space: nowrap;
    }
    form.search ul {
      list-style: none;
      margin: 0;
      padding: 0;
    }
    form.search li {
      display: inline;
      padding-right: 1em;
    }
    form.search .query {
      width: 18em;
    }
  </style>
  <link rel="stylesheet" href="Django%20%7C%20Pagination%20%7C%20Django%20Documentation_files/pygments.css" type="text/css">

	</head><body id="documentation" class="default">

	<div id="container">
		<div id="header">
			<h1 id="logo"><a href="http://www.djangoproject.com/"><img src="Django%20%7C%20Pagination%20%7C%20Django%20Documentation_files/hdr_logo.gif" alt="Django"></a></h1>
			<ul id="nav-global">
				<li id="nav-homepage"><a href="http://www.djangoproject.com/">Home</a></li>
				<li id="nav-download"><a href="http://www.djangoproject.com/download/">Download</a></li>
				<li id="nav-documentation"><a href="http://docs.djangoproject.com/">Documentation</a></li>
				<li id="nav-weblog"><a href="http://www.djangoproject.com/weblog/">Weblog</a></li>
				<li id="nav-community"><a href="http://www.djangoproject.com/community/">Community</a></li>
				<li id="nav-code"><a href="http://code.djangoproject.com/">Code</a></li>
			</ul>
		</div>
		<!-- END Header -->
		<div id="billboard">
  <h2><a href="http://docs.djangoproject.com/en/1.0/">Django documentation</a></h2>
</div>
		<div id="columnwrap">
			
		<div id="content-main">
		


  <h2 class="deck">
  
    This document describes Django version 1.0. For development documentation, 
    <a href="http://docs.djangoproject.com/en/dev/topics/pagination/">go here</a>.
  
  </h2>
  <div class="section" id="s-module-django.core.paginator">
<span id="s-topics-pagination"></span><span id="module-django.core.paginator"></span><span id="topics-pagination"></span><h1>Pagination<a class="headerlink" href="#module-django.core.paginator" title="Permalink to this headline">¶</a></h1>
<div class="versionchanged">
<span class="title">Changed in Django 1.0:</span> Pagination facilities have been almost fully reworked.</div>
<p>Django provides a few classes that help you manage paginated data – that is,
data that’s split across several pages, with “Previous/Next” links. These
classes live in <tt class="docutils literal"><span class="pre">django/core/paginator.py</span></tt>.</p>
<div class="section" id="s-example">
<span id="example"></span><h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<p>Give <a title="django.core.paginator.Paginator" class="reference internal" href="#django.core.paginator.Paginator"><tt class="xref docutils literal"><span class="pre">Paginator</span></tt></a> a list of objects, plus the number of items you’d like to
have on each page, and it gives you methods for accessing the items for each
page:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">from</span> <span class="nn">django.core.paginator</span> <span class="k">import</span> <span class="n">Paginator</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">objects</span> <span class="o">=</span> <span class="p">[</span><span class="s">'john'</span><span class="p">,</span> <span class="s">'paul'</span><span class="p">,</span> <span class="s">'george'</span><span class="p">,</span> <span class="s">'ringo'</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Paginator</span><span class="p">(</span><span class="n">objects</span><span class="p">,</span> <span class="mf">2</span><span class="p">)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">count</span>
<span class="go">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">num_pages</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">page_range</span>
<span class="go">[1, 2]</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">page1</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page1</span>
<span class="go">&lt;Page 1 of 2&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page1</span><span class="o">.</span><span class="n">object_list</span>
<span class="go">['john', 'paul']</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="mf">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">object_list</span>
<span class="go">['george', 'ringo']</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">has_next</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">has_previous</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">has_other_pages</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">next_page_number</span><span class="p">()</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">previous_page_number</span><span class="p">()</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">start_index</span><span class="p">()</span> <span class="c"># The 1-based index of the first item on this page</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">end_index</span><span class="p">()</span> <span class="c"># The 1-based index of the last item on this page</span>
<span class="go">4</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="mf">0</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">EmptyPage: That page number is less than 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="mf">3</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">EmptyPage: That page contains no results</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Note that you can give <tt class="docutils literal"><span class="pre">Paginator</span></tt> a list/tuple, a Django <tt class="docutils literal"><span class="pre">QuerySet</span></tt>, or
any other object with a <tt class="docutils literal"><span class="pre">count()</span></tt> or <tt class="docutils literal"><span class="pre">__len__()</span></tt> method. When
determining the number of objects contained in the passed object,
<tt class="docutils literal"><span class="pre">Paginator</span></tt> will first try calling <tt class="docutils literal"><span class="pre">count()</span></tt>, then fallback to using
<tt class="docutils literal"><span class="pre">len()</span></tt> if the passed object has no <tt class="docutils literal"><span class="pre">count()</span></tt> method. This allows
objects such as Django's <tt class="docutils literal"><span class="pre">QuerySet</span></tt> to use a more efficient <tt class="docutils literal"><span class="pre">count()</span></tt>
method when available.</p>
</div>
</div>
<div class="section" id="s-using-paginator-in-a-view">
<span id="using-paginator-in-a-view"></span><h2>Using <tt class="docutils literal"><span class="pre">Paginator</span></tt> in a view<a class="headerlink" href="#using-paginator-in-a-view" title="Permalink to this headline">¶</a></h2>
<p>Here's a slightly more complex example using <a title="django.core.paginator.Paginator" class="reference internal" href="#django.core.paginator.Paginator"><tt class="xref docutils literal"><span class="pre">Paginator</span></tt></a> in a view to
paginate a queryset. We give both the view and the accompanying template to
show how you can display the results. This example assumes you have a
<tt class="docutils literal"><span class="pre">Contacts</span></tt> model that has already been imported.</p>
<p>The view function looks like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">from</span> <span class="nn">django.core.paginator</span> <span class="k">import</span> <span class="n">Paginator</span><span class="p">,</span> <span class="n">InvalidPage</span><span class="p">,</span> <span class="n">EmptyPage</span>

<span class="k">def</span> <span class="nf">listing</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">contact_list</span> <span class="o">=</span> <span class="n">Contacts</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()</span>
    <span class="n">paginator</span> <span class="o">=</span> <span class="n">Paginator</span><span class="p">(</span><span class="n">contact_list</span><span class="p">,</span> <span class="mf">25</span><span class="p">)</span> <span class="c"># Show 25 contacts per page</span>

    <span class="c"># Make sure page request is an int. If not, deliver first page.</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">page</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'page'</span><span class="p">,</span> <span class="s">'1'</span><span class="p">))</span>
    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
        <span class="n">page</span> <span class="o">=</span> <span class="mf">1</span>

    <span class="c"># If page request (9999) is out of range, deliver last page of results.</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">contacts</span> <span class="o">=</span> <span class="n">paginator</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="n">page</span><span class="p">)</span>
    <span class="k">except</span> <span class="p">(</span><span class="n">EmptyPage</span><span class="p">,</span> <span class="n">InvalidPage</span><span class="p">):</span>
        <span class="n">contacts</span> <span class="o">=</span> <span class="n">paginator</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="n">paginator</span><span class="o">.</span><span class="n">num_pages</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">render_to_response</span><span class="p">(</span><span class="s">'list.html'</span><span class="p">,</span> <span class="p">{</span><span class="s">"contacts"</span><span class="p">:</span> <span class="n">contacts</span><span class="p">})</span>
</pre></div>
</div>
<p>In the template <tt class="docutils literal"><span class="pre">list.html</span></tt>, you'll want to include navigation between
pages along with any interesting information from the objects themselves:</p>
<div class="highlight-python"><pre>{% for contact in contacts.object_list %}
    {# Each "contact" is a Contact model object. #}
    {{ contact.full_name|upper }}&lt;br /&gt;
    ...
{% endfor %}

&lt;div class="pagination"&gt;
    &lt;span class="step-links"&gt;
        {% if contacts.has_previous %}
            &lt;a href="?page={{ contacts.previous_page_number }}"&gt;previous&lt;/a&gt;
        {% endif %}

        &lt;span class="current"&gt;
            Page {{ contacts.number }} of {{ contacts.paginator.num_pages }}.
        &lt;/span&gt;

        {% if contacts.has_next %}
            &lt;a href="?page={{ contacts.next_page_number }}"&gt;next&lt;/a&gt;
        {% endif %}
    &lt;/span&gt;
&lt;/div&gt;</pre>
</div>
</div>
<div class="section" id="s-paginator-objects">
<span id="paginator-objects"></span><h2><tt class="docutils literal"><span class="pre">Paginator</span></tt> objects<a class="headerlink" href="#paginator-objects" title="Permalink to this headline">¶</a></h2>
<p>The <a title="django.core.paginator.Paginator" class="reference internal" href="#django.core.paginator.Paginator"><tt class="xref docutils literal"><span class="pre">Paginator</span></tt></a> class has this constructor:</p>
<dl class="class">
<dt id="django.core.paginator.Paginator">
<!--[django.core.paginator.Paginator]-->class <tt class="descname">Paginator</tt>(<em>object_list</em>, <em>per_page</em>, <em>orphans=0</em>, <em>allow_empty_first_page=True</em>)<a class="headerlink" href="#django.core.paginator.Paginator" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<div class="section" id="s-required-arguments">
<span id="required-arguments"></span><h3>Required arguments<a class="headerlink" href="#required-arguments" title="Permalink to this headline">¶</a></h3>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">object_list</span></tt></dt>
<dd>A list, tuple, Django <tt class="docutils literal"><span class="pre">QuerySet</span></tt>, or other sliceable object with a
<tt class="docutils literal"><span class="pre">count()</span></tt> or <tt class="docutils literal"><span class="pre">__len__()</span></tt> method.</dd>
<dt><tt class="docutils literal"><span class="pre">per_page</span></tt></dt>
<dd>The maximum number of items to include on a page, not including orphans
(see the <tt class="docutils literal"><span class="pre">orphans</span></tt> optional argument below).</dd>
</dl>
</div>
<div class="section" id="s-optional-arguments">
<span id="optional-arguments"></span><h3>Optional arguments<a class="headerlink" href="#optional-arguments" title="Permalink to this headline">¶</a></h3>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">orphans</span></tt></dt>
<dd>The minimum number of items allowed on the last page, defaults to zero.
Use this when you don't want to have a last page with very few items.
If the last page would normally have a number of items less than or equal
to <tt class="docutils literal"><span class="pre">orphans</span></tt>, then those items will be added to the previous page (which
becomes the last page) instead of leaving the items on a page by
themselves. For example, with 23 items, <tt class="docutils literal"><span class="pre">per_page=10</span></tt>, and
<tt class="docutils literal"><span class="pre">orphans=3</span></tt>, there will be two pages; the first page with 10 items and
the  second (and last) page with 13 items.</dd>
<dt><tt class="docutils literal"><span class="pre">allow_empty_first_page</span></tt></dt>
<dd>Whether or not the first page is allowed to be empty.  If <tt class="xref docutils literal"><span class="pre">False</span></tt> and
<tt class="docutils literal"><span class="pre">object_list</span></tt> is  empty, then an <tt class="docutils literal"><span class="pre">EmptyPage</span></tt> error will be raised.</dd>
</dl>
</div>
<div class="section" id="s-methods">
<span id="methods"></span><h3>Methods<a class="headerlink" href="#methods" title="Permalink to this headline">¶</a></h3>
<dl class="method">
<dt id="django.core.paginator.Paginator.page">
<!--[django.core.paginator.Paginator.page]--><tt class="descclassname">Paginator.</tt><tt class="descname">page</tt>(<em>number</em>)<a class="headerlink" href="#django.core.paginator.Paginator.page" title="Permalink to this definition">¶</a></dt>
<dd>Returns a <tt class="xref docutils literal"><span class="pre">Page</span></tt> object with the given 1-based index. Raises
<tt class="xref docutils literal"><span class="pre">InvalidPage</span></tt> if the given page number doesn't exist.</dd></dl>

</div>
<div class="section" id="s-attributes">
<span id="attributes"></span><h3>Attributes<a class="headerlink" href="#attributes" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.core.paginator.Paginator.count">
<!--[django.core.paginator.Paginator.count]--><tt class="descclassname">Paginator.</tt><tt class="descname">count</tt><a class="headerlink" href="#django.core.paginator.Paginator.count" title="Permalink to this definition">¶</a></dt>
<dd><p>The total number of objects, across all pages.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">When determining the number of objects contained in <tt class="docutils literal"><span class="pre">object_list</span></tt>,
<tt class="docutils literal"><span class="pre">Paginator</span></tt> will first try calling <tt class="docutils literal"><span class="pre">object_list.count()</span></tt>. If
<tt class="docutils literal"><span class="pre">object_list</span></tt> has no <tt class="docutils literal"><span class="pre">count()</span></tt> method, then <tt class="docutils literal"><span class="pre">Paginator</span></tt> will
fallback to using <tt class="docutils literal"><span class="pre">object_list.__len__()</span></tt>. This allows objects, such
as Django's <tt class="docutils literal"><span class="pre">QuerySet</span></tt>, to use a more efficient <tt class="docutils literal"><span class="pre">count()</span></tt> method
when available.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.core.paginator.Paginator.num_pages">
<!--[django.core.paginator.Paginator.num_pages]--><tt class="descclassname">Paginator.</tt><tt class="descname">num_pages</tt><a class="headerlink" href="#django.core.paginator.Paginator.num_pages" title="Permalink to this definition">¶</a></dt>
<dd>The total number of pages.</dd></dl>

<dl class="attribute">
<dt id="django.core.paginator.Paginator.page_range">
<!--[django.core.paginator.Paginator.page_range]--><tt class="descclassname">Paginator.</tt><tt class="descname">page_range</tt><a class="headerlink" href="#django.core.paginator.Paginator.page_range" title="Permalink to this definition">¶</a></dt>
<dd>A 1-based range of page numbers, e.g., <tt class="docutils literal"><span class="pre">[1,</span> <span class="pre">2,</span> <span class="pre">3,</span> <span class="pre">4]</span></tt>.</dd></dl>

</div>
</div>
<div class="section" id="s-invalidpage-exceptions">
<span id="invalidpage-exceptions"></span><h2><tt class="docutils literal"><span class="pre">InvalidPage</span></tt> exceptions<a class="headerlink" href="#invalidpage-exceptions" title="Permalink to this headline">¶</a></h2>
<p>The <tt class="docutils literal"><span class="pre">page()</span></tt> method raises <tt class="docutils literal"><span class="pre">InvalidPage</span></tt> if the requested page is invalid
(i.e., not an integer) or contains no objects. Generally, it's enough to trap
the <tt class="docutils literal"><span class="pre">InvalidPage</span></tt> exception, but if you'd like more granularity, you can trap
either of the following exceptions:</p>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">PageNotAnInteger</span></tt></dt>
<dd>Raised when <tt class="docutils literal"><span class="pre">page()</span></tt> is given a value that isn't an integer.</dd>
<dt><tt class="docutils literal"><span class="pre">EmptyPage</span></tt></dt>
<dd>Raised when <tt class="docutils literal"><span class="pre">page()</span></tt> is given a valid value but no objects exist on that
page.</dd>
</dl>
<p>Both of the exceptions are subclasses of <tt class="docutils literal"><span class="pre">InvalidPage</span></tt>, so you can handle
them both with a simple <tt class="docutils literal"><span class="pre">except</span> <span class="pre">InvalidPage</span></tt>.</p>
</div>
<div class="section" id="s-page-objects">
<span id="page-objects"></span><h2><tt class="docutils literal"><span class="pre">Page</span></tt> objects<a class="headerlink" href="#page-objects" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt>
class <tt class="descname">Page(object_list, number, paginator):</tt></dt>
<dd></dd></dl>

<p>You usually won't construct <tt class="xref docutils literal"><span class="pre">Pages</span></tt> by hand -- you'll get them
using <a title="django.core.paginator.Paginator.page" class="reference internal" href="#django.core.paginator.Paginator.page"><tt class="xref docutils literal"><span class="pre">Paginator.page()</span></tt></a>.</p>
<div class="section" id="s-id1">
<span id="id1"></span><h3>Methods<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<dl class="method">
<dt id="django.core.paginator.Page.has_next">
<!--[django.core.paginator.Page.has_next]--><tt class="descclassname">Page.</tt><tt class="descname">has_next</tt>()<a class="headerlink" href="#django.core.paginator.Page.has_next" title="Permalink to this definition">¶</a></dt>
<dd>Returns <tt class="xref docutils literal"><span class="pre">True</span></tt> if there's a next page.</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.has_previous">
<!--[django.core.paginator.Page.has_previous]--><tt class="descclassname">Page.</tt><tt class="descname">has_previous</tt>()<a class="headerlink" href="#django.core.paginator.Page.has_previous" title="Permalink to this definition">¶</a></dt>
<dd>Returns <tt class="xref docutils literal"><span class="pre">True</span></tt> if there's a previous page.</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.has_other_pages">
<!--[django.core.paginator.Page.has_other_pages]--><tt class="descclassname">Page.</tt><tt class="descname">has_other_pages</tt>()<a class="headerlink" href="#django.core.paginator.Page.has_other_pages" title="Permalink to this definition">¶</a></dt>
<dd>Returns <tt class="xref docutils literal"><span class="pre">True</span></tt> if there's a next <em>or</em> previous page.</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.next_page_number">
<!--[django.core.paginator.Page.next_page_number]--><tt class="descclassname">Page.</tt><tt class="descname">next_page_number</tt>()<a class="headerlink" href="#django.core.paginator.Page.next_page_number" title="Permalink to this definition">¶</a></dt>
<dd>Returns the next page number. Note that this is "dumb" and will return the
next page number regardless of whether a subsequent page exists.</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.previous_page_number">
<!--[django.core.paginator.Page.previous_page_number]--><tt class="descclassname">Page.</tt><tt class="descname">previous_page_number</tt>()<a class="headerlink" href="#django.core.paginator.Page.previous_page_number" title="Permalink to this definition">¶</a></dt>
<dd>Returns the previous page number. Note that this is "dumb" and will return
the previous page number regardless of whether a previous page exists.</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.start_index">
<!--[django.core.paginator.Page.start_index]--><tt class="descclassname">Page.</tt><tt class="descname">start_index</tt>()<a class="headerlink" href="#django.core.paginator.Page.start_index" title="Permalink to this definition">¶</a></dt>
<dd>Returns the 1-based index of the first object on the page, relative to all
of the objects in the paginator's list. For example, when paginating a list
of 5 objects with 2 objects per page, the second page's <a title="django.core.paginator.Page.start_index" class="reference internal" href="#django.core.paginator.Page.start_index"><tt class="xref docutils literal"><span class="pre">start_index()</span></tt></a>
would return <tt class="docutils literal"><span class="pre">3</span></tt>.</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.end_index">
<!--[django.core.paginator.Page.end_index]--><tt class="descclassname">Page.</tt><tt class="descname">end_index</tt>()<a class="headerlink" href="#django.core.paginator.Page.end_index" title="Permalink to this definition">¶</a></dt>
<dd>Returns the 1-based index of the last object on the page, relative to all of
the objects in the paginator's list. For example, when paginating a list of
5 objects with 2 objects per page, the second page's <a title="django.core.paginator.Page.end_index" class="reference internal" href="#django.core.paginator.Page.end_index"><tt class="xref docutils literal"><span class="pre">end_index()</span></tt></a>
would return <tt class="docutils literal"><span class="pre">4</span></tt>.</dd></dl>

</div>
<div class="section" id="s-id2">
<span id="id2"></span><h3>Attributes<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.core.paginator.Page.object_list">
<!--[django.core.paginator.Page.object_list]--><tt class="descclassname">Page.</tt><tt class="descname">object_list</tt><a class="headerlink" href="#django.core.paginator.Page.object_list" title="Permalink to this definition">¶</a></dt>
<dd>The list of objects on this page.</dd></dl>

<dl class="attribute">
<dt id="django.core.paginator.Page.number">
<!--[django.core.paginator.Page.number]--><tt class="descclassname">Page.</tt><tt class="descname">number</tt><a class="headerlink" href="#django.core.paginator.Page.number" title="Permalink to this definition">¶</a></dt>
<dd>The 1-based page number for this page.</dd></dl>

<dl class="attribute">
<dt id="django.core.paginator.Page.paginator">
<!--[django.core.paginator.Page.paginator]--><tt class="descclassname">Page.</tt><tt class="descname">paginator</tt><a class="headerlink" href="#django.core.paginator.Page.paginator" title="Permalink to this definition">¶</a></dt>
<dd>The associated <a title="django.core.paginator.Paginator" class="reference internal" href="#django.core.paginator.Paginator"><tt class="xref docutils literal"><span class="pre">Paginator</span></tt></a> object.</dd></dl>

</div>
</div>
</div>



<div id="content-secondary">
  <h2 id="comments">Questions/Feedback</h2>
  <p>Having trouble? We'd like to help!</p>
  <ul>
    <li>
      Try the <a href="http://docs.djangoproject.com/en/dev/faq/">FAQ</a> — it's got answers to many common
      questions.
    </li>
    <li>
      Search for information in the <a href="http://groups.google.com/group/django-users/">archives of the
      django-users mailing list</a>, or <a href="http://groups.google.com/group/django-users/">post a question</a>.
    </li>
    <li>
      Ask a question in the <a href="irc://irc.freenode.net/">#django IRC
      channel</a>, or search the <a href="http://oebfare.com/logger/django/">IRC
      logs</a> to see if its been asked before.
    </li>
    <li>
      If you notice errors with this documentation, please <a href="http://code.djangoproject.com/simpleticket?component=Documentation">
      open a ticket</a> and let us know! Please only use the ticket tracker for
      criticisms and improvements on the docs. For tech support, use the
      resources above.
    </li>
  </ul>
</div>

		</div>
		<!-- END #content-main -->
		<div id="content-related" class="sidebar">
		
  
    <h2>Contents</h2>
    
      <ul>
<li><a class="reference external" href="">Pagination</a><ul>
<li><a class="reference external" href="#example">Example</a></li>
<li><a class="reference external" href="#using-paginator-in-a-view">Using <tt class="docutils literal"><span class="pre">Paginator</span></tt> in a view</a></li>
<li><a class="reference external" href="#paginator-objects"><tt class="docutils literal"><span class="pre">Paginator</span></tt> objects</a><ul>
<li><a class="reference external" href="#required-arguments">Required arguments</a></li>
<li><a class="reference external" href="#optional-arguments">Optional arguments</a></li>
<li><a class="reference external" href="#methods">Methods</a></li>
<li><a class="reference external" href="#attributes">Attributes</a></li>
</ul>
</li>
<li><a class="reference external" href="#invalidpage-exceptions"><tt class="docutils literal"><span class="pre">InvalidPage</span></tt> exceptions</a></li>
<li><a class="reference external" href="#page-objects"><tt class="docutils literal"><span class="pre">Page</span></tt> objects</a><ul>
<li><a class="reference external" href="#id1">Methods</a></li>
<li><a class="reference external" href="#id2">Attributes</a></li>
</ul>
</li>
</ul>
</li>
</ul>

    
  
  
  
    <h2>Search</h2>
    
    <form action="/en/1.0/search/" id="search" class="search">
  <div>
    <input name="cx" value="009763561546736975936:e88ek0eurf4" type="hidden">
    <input name="cof" value="FORID:11" type="hidden">
    <input name="ie" value="UTF-8" type="hidden">
    <input name="hl" value="" type="hidden">
    <input style="background: rgb(255, 255, 255) url(http://www.google.com/coop/intl/en/images/google_custom_search_watermark.gif) no-repeat scroll left center; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" id="id_search_q" class="query" name="q" type="text">
    <input name="sa" class="submit" value="Search" type="submit">
    <ul>
<li><label for="id_search_as_q_0"><input checked="checked" id="id_search_as_q_0" value="more:dev_docs" name="as_q" type="radio"> Latest</label></li>
<li><label for="id_search_as_q_1"><input id="id_search_as_q_1" value="more:1.0_docs" name="as_q" type="radio"> 1.0</label></li>
<li><label for="id_search_as_q_2"><input id="id_search_as_q_2" value="more:0.96_docs" name="as_q" type="radio"> 0.96</label></li>
<li><label for="id_search_as_q_3"><input id="id_search_as_q_3" value="more:all_docs" name="as_q" type="radio"> All</label></li>
</ul>
  </div>
</form>
<script type="text/javascript" src="Django%20%7C%20Pagination%20%7C%20Django%20Documentation_files/brand.html"></script>
  
  
  
    <h2>Browse</h2>
    <ul>
      
        
          <li>Prev: <a href="http://docs.djangoproject.com/en/1.0/topics/i18n/">Internationalization</a></li>
        
        
          <li>Next: <a href="http://docs.djangoproject.com/en/1.0/topics/serialization/">Serializing Django objects</a></li>
        
        <li><a href="http://docs.djangoproject.com/en/1.0/contents/">Table of contents</a></li>
        
          <li><a href="http://docs.djangoproject.com/en/1.0/genindex/">General Index</a></li>
        
          <li><a href="http://docs.djangoproject.com/en/1.0/modindex/">Global Module Index</a></li>
        
      
    </ul>
  
  
  
    <h2>You are here:</h2>
    <ul>
      
        <li>
          <a href="http://docs.djangoproject.com/en/1.0/">Django 1.0 documentation</a>
          
            <ul><li><a href="http://docs.djangoproject.com/en/1.0/topics/">Using Django</a>
          
          <ul><li>Pagination</li></ul>
          </li></ul>
        </li>
      
    </ul>
  
  
  
    <h3>Last update:</h3>
    <div>May 23, 2009, 8:15 a.m. (<a href="http://www.timeanddate.com/worldclock/city.html?n=64">CDT</a>)</div>
  

		</div>
		<!-- END #content-related -->

		</div>
		<!-- END #content -->
		<div id="footer">
			<p>© 2005-2009 <a href="http://www.djangoproject.com/foundation/">Django Software Foundation</a> unless otherwise noted. Django is a registered trademark of the Django Software Foundation. 
			Hosting graciously provided by <a href="http://mediatemple.net/">
			<img style="vertical-align: middle; position: relative; top: -1px;" src="Django%20%7C%20Pagination%20%7C%20Django%20Documentation_files/mt.png" alt="media temple"></a>
			</p>
		</div>
		<!-- END #footer -->
	</div>
	<!-- END #container -->
	</body></html>